using Blog2025.Infrastructure;
using Blog2025.Application;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

// 添加CORS支持
builder.Services.AddCors(options =>
{
    options.AddDefaultPolicy(policy =>
    {
        policy.AllowAnyOrigin()
              .AllowAnyMethod()
              .AllowAnyHeader();
    });
});


builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddApplication(builder.Configuration);

var app = builder.Build();

// 启用CORS
app.UseCors();

// 启用静态文件服务
app.UseStaticFiles();

// 为上传的文件配置静态文件服务
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads")),
    RequestPath = "/uploads"
});

// 启用认证和授权
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.Run();

